//阿里dataV屏幕适配方法，默认使用 3（全屏铺满）
(function (){
    var screenConfig = {
        width: 1920,
        height: 1080,
        display: 3
    };
    var b5config = window.b5config || {};
    window.b5config = Object.assign(screenConfig,b5config);
    $(function (){
        if(typeof(eval('GetRequest'))=="function"){
            var display_params = GetRequest('display');
            if (display_params){
                window.b5config.display = parseInt(display_params);
            }
        }
        resize();
        $(window,document).resize(function (){
            resize();
        })
    })
})();
function resize() {
    $('body').css({
        width:window.b5config.width,
        height:window.b5config.height
    })
    if (window.b5config.display === 1) { // 高度铺满，宽度100%
        resizeCenterWidth();
    } else if (window.b5config.display === 2) { // 等比缩放高度铺满
        resizeCenter();
    } else if (window.b5config.display === 3) { // 全屏铺满
        resizeFull();
    } else if (window.b5config.display === 4) { // 等比缩放高度铺满并且可以左右移动
        resizeHeight();
    } else if (window.b5config.display === 0) { // 不缩放
        resizeNone();
    } else { // 等比缩放宽度铺满
        resizeWidth();
    }
}

function resizeNone() {
    // var ratioX = window.b5config.width / $(window).width();
    // var ratioY = window.b5config.height / $(window).height();
    // var x = ratioX>1?ratioX*100:100;
    // var y = ratioY>1?ratioY*100:100;
    $('html,body').css({
        overflow: "auto",
        position: 'relative',
        backgroundSize: window.b5config.width+"px "+window.b5config.height+"px",
        backgroundPosition:"left top"
    });
    // if(x>100 || y>100){
    //     $('body').css({
    //         backgroundSize: x+"% "+y+"%",
    //         backgroundPosition:"left top"
    //     });
    // }
}

function resizeWidth() {
    var ratio = $(window).width() / (window.b5config.width || $('body').width());
    $("html").css({
        overflow: 'auto',
    })
    $('body').css({
        transform: "scale(" + ratio + ")",
        transformOrigin: "left top",
        backgroundSize: "100%",
        backgroundPosition:"left top"
    });
}

function resizeCenterWidth(){//当宽度过长时为100%，否则缩放；高度缩放
    if (!window.b5config.height || !window.b5config.width) return resizeFullBak();
    var ratioX = $(window).width() / window.b5config.width;
    var ratioY = $(window).height() / window.b5config.height;
    if(ratioX>1){
        $('body').css({
            width:'100%',
            transform: "scale(1, " + ratioY + ")",
            transformOrigin: "left top",
            backgroundSize: "100% 100%"
        });
    }else{
        $('body').css({
            transform: "scale("+ratioX+", " + ratioY + ")",
            transformOrigin: "left top",
            backgroundSize: "100% 100%"
        });
    }

}

function resizeCenter() {
    if (!window.b5config.height || !window.b5config.width) return resizeCenterBak();
    var ratio = $(window).height() / window.b5config.height;
    $('body').css({
        transform: "scale(" + ratio + ")",
        transformOrigin: "left top",
        backgroundSize: 100 * (window.b5config.width / $(window).width() * ratio) + "%" + ' 100%',
        backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top",
        marginLeft: ($(window).width() - $('body').width() * ratio) / 2
    });
}

function resizeHeight() { //
    if (!window.b5config.height || !window.b5config.width) return resizeCenterBak();
    var ratio = $(window).height() / window.b5config.height;
    $('body').css({
        transform: "scale(" + ratio + ")",
        transformOrigin: "left top",
        backgroundSize: 100 * (window.b5config.width / $(window).width() * ratio) + "%" + ' 100%',
        backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top",
        marginLeft: ($(window).width() - $('body').width() * ratio) / 2
    });
    $('html').css({
        overflowX: 'scroll'
    })
}

function resizeFull() {
    if (!window.b5config.height || !window.b5config.width) return resizeFullBak();
    var ratioX = $(window).width() / window.b5config.width;
    var ratioY = $(window).height() / window.b5config.height;
    $('body').css({
        transform: "scale(" + ratioX + ", " + ratioY + ")",
        transformOrigin: "left top",
        backgroundSize: "100% 100%"
    });
}

function resizeCenterBak() {
    var ratioX = $(window).width() / $('body').width();
    var ratioY = $(window).height() / $('body').height();
    var ratio = Math.min(ratioX, ratioY);
    $('body').css({
        transform: "scale(" + ratio + ")",
        transformOrigin: "left top",
        backgroundSize: (1 / ratioX) * 100 * ratio + "%",
        backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top",
        marginLeft: ($(window).width() - $('body').width() * ratio) / 2
    });
}

function resizeFullBak() {
    var ratioX = $(window).width() / $('body').width();
    var ratioY = $(window).height() / $('body').height();
    $('body').css({
        transform: "scale(" + ratioX + ", " + ratioY + ")",
        transformOrigin: "left top",
        backgroundSize: "100% " + ratioY * 100 + "%"
    });
}